package com.neteast.androidclient.newscenter.receiver;

import com.neteast.androidclient.newscenter.service.NetService;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.widget.Toast;

public class WifiStateReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		Intent netService=new Intent(context, NetService.class);
		if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
			WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
			// wifi已经连接上，启动netService
			if (wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
				Toast.makeText(context, "您正在使用wifi上网", Toast.LENGTH_SHORT).show();
				context.startService(netService);
			}
			// wifi没有连接上，如果此时客户端启动，那么停止客户端
			else {
				Toast.makeText(context, "wifi链接断开", Toast.LENGTH_SHORT).show();
				context.stopService(netService);
			}
		}
	}

}
